import jwt

class Myjwt:
    def __init__(self):
        self.SECRET_KEY = '曹宝福牛逼呀呀呀'

    #生成jwt
    def jwt_encode(self,data):
        token = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
        return token

        #解密jwt
    def jwt_decode(self,token):
        try:
            data = jwt.decode(token,self.SECRET_KEY,algorithms='HS256')
            #重新加密获取新的token
            # return data
            newtoken = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
            return newtoken
        except:
            return None

    def check(self,token,newtoken):
        if token == newtoken:
            return True
        return False

myjwt = Myjwt()

# token = myjwt.jwt_encode({'data':{'name':'曹宝福'}})
# print(token)
# newtoken = myjwt.jwt_decode('233242424')
# flag = myjwt.check(token,newtoken)

